home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / after / ltchars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.5 KB  |  72 lines

  1. /*
  2.  * illustrates the use of extended tty charatersitics
  3.  *
  4.  * If _ABI_SOURCE is defined, use the ``termios'' structure and
  5.  * provided routines instead of the ``ltchars'' struct
  6.  */
  7. #ifdef _ABI_SOURCE
  8. #define SVR4
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <sys/types.h>
  13. #ifdef SVR4
  14. #include <sys/termios.h>
  15. #else
  16. #include <sys/ioctl.h>
  17. #endif
  18.  
  19. #ifdef SVR4
  20. struct termios old_tty, new_tty;
  21. #else
  22. #ifdef TIOCSLTC
  23. struct ltchars old_chars, new_chars;
  24. #endif
  25. #endif
  26.  
  27. main () 
  28. {
  29. #ifdef SVR4
  30.     /*
  31.      * save off ltchars settings,
  32.      * and change some - SVR4 flavor
  33.      */
  34.     tcgetattr (fileno (stdin), &old_tty);
  35.     new_tty = old_tty;
  36.     if (old_tty.c_cc[VLNEXT] == CTRL('v'))
  37.         new_tty.c_cc[VLNEXT] = -1;
  38.     if (old_tty.c_cc[VRPRNT] == CTRL('r'))
  39.         new_tty.c_cc[VRPRNT] = -1;
  40.     tcsetattr (fileno (stdin), TCSAFLUSH, &new_tty);
  41. #else /* !SVR4 */
  42. #ifdef TIOCSLTC
  43.     /*
  44.      * save off ltchars settings,
  45.      * and change some
  46.      */
  47.     (void)ioctl(fileno(stdin), TIOCGLTC, (char *)&old_chars);
  48.     new_chars = old_chars;
  49.     if (old_chars.t_lnextc == ctl('v'))
  50.         new_chars.t_lnextc = -1;
  51.     if (old_chars.t_rprntc == ctl('r'))
  52.         new_chars.t_rprntc = -1;
  53.     (void)ioctl(fileno(stdin), TIOCSLTC, (char *)&new_chars);
  54. #endif
  55. #endif
  56. }
  57.  
  58. /*
  59.  * on program exit, restore old ltchars settings
  60.  */
  61. void
  62. on_quit()
  63. {
  64. #ifdef SVR4
  65.     tcsetattr (fileno (stdin), TCSAFLUSH, &old_tty);
  66. #else /* !SVR4 */
  67. #ifdef TIOCSLTC
  68.     (void)ioctl(fileno(stdin), TIOCSLTC, (char *)&old_chars);
  69. #endif
  70. #endif
  71. }
  72.